import 'package:dmz/base/pageWidget/base_stateful_widget.dart';
import 'package:dmz/base/widget/defult_widget.dart';
import 'package:dmz/business/home/controller/share_moto_controller.dart';
import 'package:dmz/business/home/model/moto_model.dart';
import 'package:dmz/string_res/str_res_keys.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../mine/model/share_model.dart';

class ShareMotoWidgets {
  static Widget backGroundWidget(Widget child) {
    return Container(
      decoration: const BoxDecoration(
          gradient: LinearGradient(
        begin: Alignment.topCenter, // 渐变起始位置
        end: Alignment.bottomCenter, // 渐变结束位置
        colors: [
          Color(0xFF000000),
          Color(0xFF050505),
          Color(0xFF2C2D35)
        ], // 渐变色数组
      )),
      child: child,
    );
  }

  static Widget deviceInfor(MotoModel data) {
    Map<String, String> titles = {
      '车型'.tr: data.type_name ?? '',
      '颜色'.tr: data.color ?? '',
      'SN': data.sn_code ?? '',
      '车架号'.tr: data.frame_code ?? '',
    };

    topWidget() {
      return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
        Row(mainAxisAlignment: MainAxisAlignment.start, children: [
          Image.asset('assets/images/home/share/signal.png',
                  width: 56.sp, height: 56.sp)
              .marginOnly(right: 20.sp),
          DefaultText('4G版'.tr, 32.sp, textColor: Colors.white)
        ]).marginOnly(bottom: 20.sp),
        DefaultText(data.name ?? '', 48.sp,
            fontWeight: FontWeight.w700, textColor: Colors.white)
      ]).marginOnly(left: 32.sp, right: 32.sp);
    }

    inforItem(String title, String contnet) {
      return Column(children: [
        Row(children: [
          Container(
              width: 110.sp,
              height: 53.sp,
              child:
                  DefaultText(title, 35.sp, textColor: const Color(0xB3F9F9F9))
                      .marginOnly(right: 22.sp)),
          DefaultText(contnet, 35.sp,
              textColor: const Color(0xB3F9F9F9), fontWeight: FontWeight.w700)
        ]).marginOnly(top: 30.sp, bottom: 32.sp, left: 32.sp, right: 32.sp),
        Container(height: 1.sp, color: Color(0xFF2C2D35))
      ]);
    }

    Widget inforBottom() {
      return Column(
          children: titles.keys
              .map((key) => inforItem(key, titles[key] ?? ''))
              .toList());
    }

    return Stack(
      children: [
        Container(
            padding: EdgeInsets.only(top: 36.sp),
            color: const Color(0xFF434650),
            child: Column(children: [topWidget(), inforBottom()])),
        Positioned(
            right: 0,
            top: 32.sp,
            child: DefaultNetWorkImage(data.photo ?? '',
                width: 320.sp, height: 254.sp))
      ],
    );
  }

  static Widget midelWiedget(Function(int) clickAction) {
    item(int type) {
      return Container(
              color: Colors.transparent,
              child: Row(
                children: [
                  Image.asset(
                          type == 0
                              ? 'assets/images/home/share/phone_icon.png'
                              : 'assets/images/home/share/address_icon.png',
                          width: 112.sp,
                          height: 112.sp)
                      .marginOnly(right: 20.sp),
                  Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        DefaultText(
                                type == 0 ? '搜索手机号进行分享'.tr : '获取手机通讯录进行分享'.tr,
                                40.sp,
                                textColor: Colors.white,
                                fontWeight: FontWeight.w700)
                            .marginOnly(bottom: 22.sp),
                        DefaultText(
                            type == 0
                                ? '通过输入对方的注册账号的手机号进行分享'.tr
                                : '通过获取通讯录选择指定通讯录中的人进行分享'.tr,
                            28.sp,
                            textColor: Colors.white)
                      ]),
                  const Expanded(child: SizedBox()),
                  Image.asset('assets/images/home/share/right_icon.png',
                      width: 18.sp, height: 30.sp)
                ],
              ).paddingOnly(top: 36.sp, bottom: 36.sp))
          .addGestureDetector(() => clickAction(type));
    }

    return Container(
        padding: EdgeInsets.only(left: 32.sp, right: 32.sp),
        color: const Color(0xFF434650),
        child: Column(children: [
          item(0),
          Container(color: const Color(0x4DD8D8D8), height: 1.sp),
          item(1)
        ])).marginOnly(top: 20.sp);
  }

  static Widget bottomWidget() {
    return GetBuilder<ShareMotoController>(
        id: 'shareList',
        builder: (controller) {
          return Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                DefaultText(
                        SR.sharePerson
                            .replaceAll('xxxx', '${controller.total}'),
                        32.sp,
                        textColor: const Color(0xB3FFFFFF))
                    .marginOnly(left: 32.sp),
                controller.total > 0
                    ? shareListWidget(controller.shareList)
                    : contentEmpty()
              ]).marginOnly(top: 40.sp);
        });
  }

  static contentEmpty() {
    return Center(
        child: Column(children: [
      Image.asset('assets/images/home/share/empty_image.png',
          width: 360.sp, height: 298.sp),
      DefaultText(
        '车辆未分享给其他人'.tr,
        40.sp,
        fontWeight: FontWeight.w700,
        textColor: Colors.white,
      ).marginOnly(top: 32.sp)
    ])).marginOnly(top: 32.sp, bottom: 112.sp);
  }

  static shareListWidget(List<ShareModel> datas) {
    item(ShareModel data) {
      return Container(
          alignment: Alignment.center,
          padding: EdgeInsets.only(
              left: 32.sp, right: 32.sp, top: 48.sp, bottom: 48.sp),
          color: const Color(0xFF434650),
          child: Row(children: [
            Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
              DefaultText(data.name ?? '', 40.sp,
                      fontWeight: FontWeight.w700, textColor: Colors.white)
                  .marginOnly(bottom: 22.sp),
              DefaultText(data.phone ?? '', 28.sp, textColor: Colors.white)
            ]),
            const Expanded(child: SizedBox()),
            DefaultText('等待确认'.tr, 32.sp, textColor: const Color(0xFF00E3FF))
          ]));
    }

    return ListView.builder(
        physics: const NeverScrollableScrollPhysics(),
        shrinkWrap: true,
        itemCount: datas.length,
        itemBuilder: (context, index) {
          return item(datas[index]);
        }).marginOnly(top: 32.sp);
  }
}
